package com.ruoyi.web.controller.market.account;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.model.param.ChannelInfoParam;
import com.ruoyi.extend.service.IChannelInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.AccountItemChannle;
import com.ruoyi.account.service.IAccountItemChannleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.AccountItemChannleWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 渠道账户信息Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@Controller
@RequestMapping("/account/itemChannle")
public class AccountItemChannleController extends BaseController
{
    private String prefix = "account/itemChannle";

    @Autowired
    private IAccountItemChannleService accountItemChannleService;
    @Autowired
    private IChannelInfoService channelInfoService;

    @RequiresPermissions("account:itemChannle:view")
    @GetMapping()
    public String itemChannle(ModelMap modelMap)
    {
        ChannelInfoParam channelInfoParam = new ChannelInfoParam();
        List<Map<String, String>> channelInfoList = channelInfoService.selectSimpleMapInfo(channelInfoParam);
        modelMap.put("channelInfoList", channelInfoList);

        return prefix + "/itemChannle";
    }

    /**
     * 查询渠道账户信息列表
     */
    @RequiresPermissions("account:itemChannle:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountItemChannle accountItemChannle)
    {
        startPage();
        List<Map<String, Object>> mapList = accountItemChannleService.selectAccountItemChannleListMap(accountItemChannle);
        mapList = new AccountItemChannleWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出渠道账户信息列表
     */
    @RequiresPermissions("account:itemChannle:export")
    @Log(title = "渠道账户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccountItemChannle accountItemChannle)
    {
        List<AccountItemChannle> list = accountItemChannleService.selectAccountItemChannleList(accountItemChannle);
        ExcelUtil<AccountItemChannle> util = new ExcelUtil<AccountItemChannle>(AccountItemChannle.class);
        return util.exportExcel(list, "渠道账户信息数据");
    }

    /**
     * 新增渠道账户信息
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {

        ChannelInfoParam channelInfoParam = new ChannelInfoParam();
        List<Map<String, String>> channelInfoList = channelInfoService.selectSimpleMapInfo(channelInfoParam);
        modelMap.put("channelInfoList", channelInfoList);

        return prefix + "/add";
    }

    /**
     * 新增保存渠道账户信息
     */
    @RequiresPermissions("account:itemChannle:add")
    @Log(title = "渠道账户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountItemChannle accountItemChannle)
    {
        return toAjax(accountItemChannleService.insertAccountItemChannle(accountItemChannle));
    }

    /**
     * 修改渠道账户信息
     */
    @RequiresPermissions("account:itemChannle:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AccountItemChannle accountItemChannle = accountItemChannleService.selectAccountItemChannleById(id);
        mmap.put("accountItemChannle", accountItemChannle);
        return prefix + "/edit";
    }

    /**
     * 修改保存渠道账户信息
     */
    @RequiresPermissions("account:itemChannle:edit")
    @Log(title = "渠道账户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountItemChannle accountItemChannle)
    {
        return toAjax(accountItemChannleService.updateAccountItemChannle(accountItemChannle));
    }

    /**
     * 删除渠道账户信息
     */
    @RequiresPermissions("account:itemChannle:remove")
    @Log(title = "渠道账户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountItemChannleService.deleteAccountItemChannleByIds(ids));
    }
}
